
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>模块 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="标准库.html" />
    
    
    <link rel="prev" href="IO编程.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="基础.html">
            
                <a href="基础.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="字符串处理.html">
            
                <a href="字符串处理.html">
            
                    
                    字符串处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="数据结构.html">
            
                <a href="数据结构.html">
            
                    
                    数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="数据结构高级内容.html">
            
                <a href="数据结构高级内容.html">
            
                    
                    数据结构高级内容
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="函数式编程.html">
            
                <a href="函数式编程.html">
            
                    
                    函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="面向对象编程.html">
            
                <a href="面向对象编程.html">
            
                    
                    面向对象编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="类的特殊方法.html">
            
                <a href="类的特殊方法.html">
            
                    
                    类的特殊方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="异常处理.html">
            
                <a href="异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="IO编程.html">
            
                <a href="IO编程.html">
            
                    
                    IO编程
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.12" data-path="模块.html">
            
                <a href="模块.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="标准库.html">
            
                <a href="标准库.html">
            
                    
                    标准库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="测试.html">
            
                <a href="测试.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="调试.html">
            
                <a href="调试.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >模块</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x6A21;&#x5757;">&#x6A21;&#x5757;</h1>
<hr>
<h2 id="&#x6A21;&#x5757;&#xFF08;module&#xFF09;">&#x6A21;&#x5757;&#xFF08;Module&#xFF09;</h2>
<p>&#x5728; Python &#x4E2D;&#xFF0C;&#x4E00;&#x4E2A;.py &#x6587;&#x4EF6;&#x5C31;&#x79F0;&#x4E4B;&#x4E3A;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF08; Module&#xFF09;&#x3002;&#x6A21;&#x5757;&#x540D;&#xFF08;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF09;&#x53EF;&#x4EE5;&#x7531;&#x5168;&#x5C40;&#x53D8;&#x91CF; <code>__name__</code> &#x5F97;&#x5230;&#x3002;&#x4EFB;&#x4F55;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x90FD;&#x88AB;&#x89C6;&#x4E3A;&#x6A21;&#x5757;&#x7684;&#x6587;&#x6863;&#x6CE8;&#x91CA;&#x3002;&#x6A21;&#x5757;&#x5982;&#x679C;&#x5305;&#x542B;&#x53EF;&#x6267;&#x884C;&#x7684;&#x8BED;&#x53E5;&#xFF08;&#x4E00;&#x822C;&#x7528;&#x6765;&#x521D;&#x59CB;&#x5316;&#x6A21;&#x5757;&#xFF09;&#xFF0C;&#x5B83;&#x4EEC;&#x4EC5;&#x5728; &#x7B2C;&#x4E00;&#x6B21; &#x88AB;&#x5BFC;&#x5165;&#x7684;&#x5730;&#x65B9;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x3002;  </p>
<p>&#x89E3;&#x91CA;&#x5668;&#x641C;&#x7D22;&#x6A21;&#x5757;&#x7684;&#x987A;&#x5E8F;&#xFF1A;  </p>
<ul>
<li>&#x5148;&#x5728;built-in&#x6A21;&#x5757;&#x4E2D;&#x67E5;&#x627E;;  </li>
<li>&#x5982;&#x679C;&#x6CA1;&#x627E;&#x5230;&#xFF0C;&#x5219;&#x5728;<code>sys.path</code>&#x63D0;&#x4F9B;&#x7684;&#x8DEF;&#x5F84;&#x5217;&#x8868;&#x4E2D;&#x7EE7;&#x7EED;&#x67E5;&#x627E;&#x3002;</li>
</ul>
<p><code>sys.path</code>&#x88AB;&#x521D;&#x59CB;&#x5316;&#x4E3A;&#x5982;&#x4E0B;&#x8DEF;&#x5F84;&#xFF1A;
1&#xFF09;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#xFF1B;<br>2&#xFF09;&#x73AF;&#x5883;&#x53D8;&#x91CF;<code>PYTHONPATH</code>&#xFF1B;<br>3&#xFF09;&#x9ED8;&#x8BA4;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#xFF1B;  </p>
<blockquote>
<p>&#x6CE8;&#xFF1A;
&#x4F7F;&#x7528;import&#x53EA;&#x80FD;&#x5BFC;&#x5165;&#x5305;&#x6216;&#x6A21;&#x5757;;<br>&#x4F7F;&#x7528;from ... import ...&#x53EF;&#x4EE5;&#x5BFC;&#x5165;&#x5305;&#x3001;&#x6A21;&#x5757;&#x3001;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#x7684;&#x7B26;&#x53F7;&#xFF08;&#x7C7B;&#x3001;&#x51FD;&#x6570;&#x3001;&#x53D8;&#x91CF;&#x7B49;&#xFF09;&#x3002;  </p>
</blockquote>
<h2 id="&#x5305;&#xFF08;-package&#xFF09;">&#x5305;&#xFF08; Package&#xFF09;</h2>
<p>&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x6A21;&#x5757;&#x540D;&#x51B2;&#x7A81;&#xFF0C; Python &#x53C8;&#x5F15;&#x5165;&#x4E86;&#x6309;&#x76EE;&#x5F55;&#x6765;&#x7EC4;&#x7EC7;&#x6A21;&#x5757;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x79F0;&#x4E3A;&#x5305;&#xFF08; Package&#xFF09;&#x3002;  </p>
<blockquote>
<p>&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x5305;&#x76EE;&#x5F55;&#x4E0B;&#x9762;&#x90FD;&#x4F1A;&#x6709;&#x4E00;&#x4E2A; <code>__init__.py</code> &#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x662F;&#x5FC5;&#x987B;&#x5B58;&#x5728;&#x7684;&#xFF1B;&#x5426;&#x5219;&#xFF0C; Python &#x5C31;&#x628A;&#x8FD9;&#x4E2A;&#x76EE;&#x5F55;&#x5F53;&#x6210;&#x666E;&#x901A;&#x76EE;&#x5F55;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5305;&#x3002;<br><code>__init__.py</code> &#x53EF;&#x4EE5;&#x662F;&#x7A7A;&#x6587;&#x4EF6;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x6709; Python &#x4EE3;&#x7801;&#xFF0C;&#x56E0;&#x4E3A; <code>__init__.py</code> &#x672C;&#x8EAB;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x800C;&#x5B83;&#x7684;&#x6A21;&#x5757;&#x540D;&#x5C31;&#x662F;&#x5B83;&#x7684;&#x7236;&#x76EE;&#x5F55;&#x540D;&#x3002;  </p>
</blockquote>
<h2 id="&#x4F5C;&#x7528;&#x57DF;&#x4E00;&#x822C;&#x7EA6;&#x5B9A;">&#x4F5C;&#x7528;&#x57DF;&#x4E00;&#x822C;&#x7EA6;&#x5B9A;</h2>
<p>&#x7C7B;&#x4F3C;<code>__xxx__</code>&#x8FD9;&#x6837;&#x7684;&#x53D8;&#x91CF;&#x662F;&#x7279;&#x6B8A;&#x53D8;&#x91CF;&#xFF0C;&#x53EF;&#x4EE5;&#x88AB;&#x76F4;&#x63A5;&#x5F15;&#x7528;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x7279;&#x6B8A;&#x7528;&#x9014;&#xFF1B;<br>&#x7C7B;&#x4F3C;<code>_xxx</code> &#x548C;<code>__xxx</code> &#x8FD9;&#x6837;&#x7684;&#x51FD;&#x6570;&#x6216;&#x53D8;&#x91CF;&#x5C31;&#x662F;&#x975E;&#x516C;&#x5F00;&#x7684;&#xFF08; private&#xFF09;&#xFF0C;&#x4E0D;&#x5E94;&#x8BE5;&#x88AB;&#x76F4;&#x63A5;&#x5F15;&#x7528;&#xFF1B;  </p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="IO编程.html" class="navigation navigation-prev " aria-label="Previous page: IO编程">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="标准库.html" class="navigation navigation-next " aria-label="Next page: 标准库">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"模块","level":"1.12","depth":1,"next":{"title":"标准库","level":"1.13","depth":1,"path":"标准库.md","ref":"标准库.md","articles":[]},"previous":{"title":"IO编程","level":"1.11","depth":1,"path":"IO编程.md","ref":"IO编程.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"模块.md","mtime":"2017-08-22T15:18:36.921Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-08-27T04:11:18.522Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

